﻿using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Diagnostics;
using NCRE学生考试端V1._0.悬浮框;
using Model;
using BLL;
//using System.Text
//using System.Runtime.InteropServices
//using System.Collections.Generic
//using System.Data.SqlClient
//using System.Threading
//using Microsoft.Win32
//using System.Linq
//using System.Text
//using NCRE学生考试端V1._0.选择题







namespace NCRE学生考试端V1._0
{
    public partial class frmMain2 : Form
    {
        public static Form frmmain2;

        #region 构造函数 修改人：李金颖-隐藏窗体控制按钮-2018-12-8 10:43:23
        public frmMain2()
        {
            InitializeComponent();
            frmmain2 = this;
            this.ControlBox = false;//隐藏窗体上的控制按钮（最小化、最大化、关闭）
        }
        #endregion

        //private static FrmLogin instanceLogin


        //实例化一个学生实体
        public StudentInfoEntity studentinfo { get; set; }

        /// <summary>
        /// 加载学生信息
        /// </summary>
        public static StudentInfoEntity st { get; set; }

        /// <summary>
        /// 重载方法让窗体上的关闭按钮不可用-2015年12月14日19:49:39
        /// </summary>
        /// <param name="e"></param>
        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);
            e.Cancel = true;
            
            //frmxuanfukuang frmxfk = new frmxuanfukuang()
            //frmxfk.showbtn()
            //this.Hide()
        }

        


        private void frmMain2_Load(object sender, EventArgs e)
        {
            //txtWin.BackColor = Color.LightSeaGreen
            //txtWord.BackColor = Color.LightSteelBlue
            //txtExcel.BackColor = Color.LightSeaGreen
            //txtIE.BackColor = Color.
            //txtPPT.BackColor = Color.DeepPink
            //确定操作题窗体的位置--周洲--2015-12-13
            this.Top = 0;
            this.Left = 0;
            Rectangle ScreenArea = System.Windows.Forms.Screen.GetWorkingArea(this);
            this.Height = ScreenArea.Height;

            //确定所有的显示题txt的高度
            txtWin.Height = ScreenArea.Height - 200;
            txtWord.Height = ScreenArea.Height - 200;
            txtPPT.Height = ScreenArea.Height - 200;
            txtIE.Height = ScreenArea.Height - 200;
            txtExcel.Height = ScreenArea.Height - 200;
            //上一步不可用
            button3.Visible = false;

            //打开IE浏览器不可用
            btnIE.Visible = false;


            //大题打开后默认Windows题框为红色--白爱民--2018-12-8:14:25：56
            label1.ForeColor = System.Drawing.Color.Red;


            #region 利用全局变量，从题库中加载word试题--周洲--2015年11月21日
            //定义一个word助手类
            WordLoadinfo wordhelper = new WordLoadinfo();
            //定义一个题库类传递Papertype
            WordQuestionEntity wordinfo = new WordQuestionEntity();
            wordinfo.PaperType = MyInfo.MyPaperType();
            //调用word试题load的方法
            DataTable worddt = wordhelper.SelectTestByPaperType();
            //将从数据库中取出的字段赋给一个字符串
            string newLine = null;

            //循环DataTable取出里面的值
            for (int i = 0; i < worddt.Rows.Count; i++)
            {
                newLine += worddt.Rows[i]["QuestionContent"].ToString();

            }
            //让字符串按照规律 赋给文本框 
            string[] s = newLine.Split('。');
            for (int i = 0; i < s.Length; i++)            {
                
                txtWord.Text += s[i] + "\r\n";
            }
            #endregion

            #region 利用全局变量，从题库中加载Excel试题--周洲--2015年11月21日

            ExcelLoading excelhelper = new ExcelLoading();
            //ExcelEntityBll excelentitybll = new ExcelEntityBll()
            ExcelQuestionEntity excelinfo = new ExcelQuestionEntity();

            excelinfo.PaperType = MyInfo.MyPaperType();
            DataTable exceldt = excelhelper.LoadQuestionContent(excelinfo);
            //将从数据库中取出的字段赋给一个字符串
            string newExcelContent = null;
            //循环DataTable取出里面的值
            for (int i = 0; i < exceldt.Rows.Count; i++)
            {
                newExcelContent += exceldt.Rows[i]["QuestionContent"].ToString();
            }
            //让字符串按照规律 赋给文本框 
            string[] sE = newExcelContent.Split('。');
            for (int i = 0; i < sE.Length; i++)
            {
                txtExcel.Text += sE[i] + "\r\n";
            }
            #endregion

            #region 利用全局变量，从题库中加载windows试题--周洲--2015年11月21日
            //定义一个windows助手类
            WindowsLoadInfo windowsHelper = new WindowsLoadInfo();
            //定义一个Windows题库类
            WinQuestionEntity wininfo = new WinQuestionEntity();
            wininfo.paperType = MyInfo.MyPaperType();
            //调用WindowsLoadInfo中的LoadQuestionContent方法
            DataTable winQuestionDt = windowsHelper.LoadQuestionContent(wininfo);
            //将从数据库中取出的字段赋给一个字符串
            string newWinContent = null;
            //循环winQuestionDt取出里面的所有值
            for (int i = 0; i < winQuestionDt.Rows.Count; i++)
            {

                newWinContent += winQuestionDt.Rows[i]["questionContent"].ToString();
            }
            //让字符串按照规律 赋给文本框 
            string[] sW = newWinContent.Split('。');
            for (int i = 0; i < sW.Length; i++)
            {
                txtWin.Text += sW[i] + "\r\n";
            }
            #endregion

            #region 利用全局变量，从题库中加载IE试题--周洲--2015年11月21日
            //定义一个windows助手类
            IELoadInfo ieHelper = new IELoadInfo();
            //定义一个Windows题库类
            IEQuestionEntity ieinfo = new IEQuestionEntity();
            //调用WindowsLoadInfo中的LoadQuestionContent方法
            ieinfo.paperType = MyInfo.MyPaperType();
            DataTable ieQuestionDt = ieHelper.LoadQuestionContent(ieinfo);
            //将从数据库中取出的字段赋给一个字符串
            string newIEContent = null;
            //循环ieQuestionDt取出里面的所有值
            for (int i = 0; i < ieQuestionDt.Rows.Count; i++)
            {
                newIEContent += ieQuestionDt.Rows[i]["questionContent"].ToString();
            }
            //让字符串按照规律 赋给文本框 
            string[] sIE = newIEContent.Split('。');
            for (int i = 0; i < sIE.Length; i++)
            {
                txtIE.Text += sIE[i] + "\r\n";
            }
            #endregion

            #region 利用全局变量，从题库中加载PPT试题--周洲--2015年11月21日
            //定义一个PPT助手类
            PptLoadinfo ppthelper = new PptLoadinfo();
            //定义一个PPT题库类
            PptQuestionEntity pptinfo = new PptQuestionEntity();
            pptinfo.PaperType = MyInfo.MyPaperType();
            //调用PPTLoadInfo中的LoadQuestionContent方法
            DataTable pptDt = ppthelper.LoadQuestionContent(pptinfo);
            //将从数据库中取出的字段赋给一个字符串
            string newPPTContent = null;
            //循环ieQuestionDt取出里面的所有值
            for (int i = 0; i < pptDt.Rows.Count; i++)
            {
                newPPTContent += pptDt.Rows[i]["QuestionContent"].ToString();
            }
            //让字符串按照规律 赋给文本框 
            string[] sPPT = newPPTContent.Split('。');
            for (int i = 0; i < sPPT.Length; i++)
            {
                txtPPT.Text += sPPT[i] + "\r\n";
            }
            #endregion
        }


        //修改人：刘檬-点击上一题，对其他label颜色修改为黑色-2018年12月16日11:19:48
        /// <summary>
        /// 上一题
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            //判断当前页面是哪个，切换到上个题
            if (txtWord.Visible == true)
            {
                button2.Visible = true;
                button3.Visible = false;
                button1.Visible = true;
                //  当前显示操作系统题

                label1.ForeColor = System.Drawing.Color.Red;
                label2.ForeColor = System.Drawing.Color.Black;
                label3.ForeColor = System.Drawing.Color.Black;
                label4.ForeColor = System.Drawing.Color.Black;
                label5.ForeColor = System.Drawing.Color.Black;
                txtWin.Visible = true;
                txtWord.Visible = false;
                txtExcel.Visible = false;
                txtIE.Visible = false;
                txtPPT.Visible = false;
            }

            else if (txtExcel.Visible == true)
            {
                button1.Visible = false;
                button2.Visible = true;
                button3.Visible = true;
                //当前显示word题目
                label1.ForeColor = System.Drawing.Color.Black;
                label2.ForeColor = System.Drawing.Color.Red;
                label3.ForeColor = System.Drawing.Color.Black;
                label4.ForeColor = System.Drawing.Color.Black;
                label5.ForeColor = System.Drawing.Color.Black;
                txtWord.Visible = true;
                txtExcel.Visible = false;
                txtPPT.Visible = false;
                txtIE.Visible = false;
                txtWin.Visible = false;
            }
            else if (txtPPT.Visible == true)
            {
                button1.Visible = false;
                button2.Visible = true;
                button3.Visible = true;
                //当前显示Excel题
                label1.ForeColor = System.Drawing.Color.Black;
                label2.ForeColor = System.Drawing.Color.Black;
                label3.ForeColor = System.Drawing.Color.Red;
                label4.ForeColor = System.Drawing.Color.Black;
                label5.ForeColor = System.Drawing.Color.Black;
                txtExcel.Visible = true;
                txtPPT.Visible = false;
                txtIE.Visible = false;
                txtWord.Visible = false;
                txtWin.Visible = false;
            }
            else if (txtIE.Visible == true)
            {
                button1.Visible = false;
                button2.Visible = true;
                button3.Visible = true;
                btnIE.Visible = false;
                //当前显示ppt的题
                label1.ForeColor = System.Drawing.Color.Black;
                label2.ForeColor = System.Drawing.Color.Black;
                label3.ForeColor = System.Drawing.Color.Black;
                label4.ForeColor = System.Drawing.Color.Red;
                label5.ForeColor = System.Drawing.Color.Black;
                txtPPT.Visible = true;
                txtIE.Visible = false;
                txtExcel.Visible = false;
                txtWord.Visible = false;
                txtWin.Visible = false;
            }
        }

        //修改人：刘檬-点击下一题，对其他label颜色修改为黑色-2018年12月16日11:19:48
        /// <summary>
        /// 下一题
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            //判断当前页面是哪个，切换到下个题
            if (txtWin.Visible == true)
            {
                button3.Visible = true;
                button2.Visible = true;
                button1.Visible = false;
                btnIE.Visible = false;
                //当前显示word题
                label1.ForeColor = System.Drawing.Color.Black;
                label2.ForeColor = System.Drawing.Color.Red;
                label3.ForeColor = System.Drawing.Color.Black;
                label4.ForeColor = System.Drawing.Color.Black;
                label5.ForeColor = System.Drawing.Color.Black;
                txtWord.Visible = true;
                txtWin.Visible = false;
                txtPPT.Visible = false;
                txtIE.Visible = false;
                txtExcel.Visible = false;
            }

            else if (txtWord.Visible == true)
            {
                button1.Visible = false;
                button3.Visible = true;
                button2.Visible = true;
                btnIE.Visible = false;
                //当前显示Excel题
                label1.ForeColor = System.Drawing.Color.Black;
                label2.ForeColor = System.Drawing.Color.Black;
                label3.ForeColor = System.Drawing.Color.Red;
                label4.ForeColor = System.Drawing.Color.Black;
                label5.ForeColor = System.Drawing.Color.Black;
                txtExcel.Visible = true;
                txtWord.Visible = false;
                txtWin.Visible = false;
                txtIE.Visible = false;
                txtPPT.Visible = false;
            }

            else if (txtExcel.Visible == true)
            {
                button1.Visible = false;
                button3.Visible = true;
                button2.Visible = true;
                btnIE.Visible = false;
                //当前显示PPT题
                label1.ForeColor = System.Drawing.Color.Black;
                label2.ForeColor = System.Drawing.Color.Black;
                label3.ForeColor = System.Drawing.Color.Black;
                label4.ForeColor = System.Drawing.Color.Red;
                label5.ForeColor = System.Drawing.Color.Black;
                txtPPT.Visible = true;
                txtExcel.Visible = false;
                txtWord.Visible = false;
                txtIE.Visible = false;
                txtWin.Visible = false;
            }
            else if (txtPPT.Visible == true)
            {
                button1.Visible = false;
                button2.Visible = false;
                button3.Visible = true;
                btnIE.Visible = true;
                //当前显示IE题
                label1.ForeColor = System.Drawing.Color.Black;
                label2.ForeColor = System.Drawing.Color.Black;
                label3.ForeColor = System.Drawing.Color.Black;
                label4.ForeColor = System.Drawing.Color.Black;
                label5.ForeColor = System.Drawing.Color.Red;

                txtIE.Visible = true;
                txtPPT.Visible = false;
                txtWin.Visible = false;
                txtWord.Visible = false;
                txtExcel.Visible = false;

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //点击选择题隐藏悬浮框
            frmxuanfukuang.frmxuanfuk.Visible = false;
            //调回到选择题
            this.Hide();
            FrmMain.frmmain.Visible = true;
        }
        //修改人：刘檬-点击label事件不修改其他label颜色（黑色）-2018年12月16日11:19:48
        private void label5_Click(object sender, EventArgs e)
        {

            //当前显示IE题
            button1.Visible = false;
            button2.Visible = false;
            button3.Visible = true;
            btnIE.Visible = true;
            button1.Visible = false;
            button2.Visible = false;
            button3.Visible = true;
            btnIE.Visible = true;
            label1.ForeColor = System.Drawing.Color.Black;
            label2.ForeColor = System.Drawing.Color.Black;
            label3.ForeColor = System.Drawing.Color.Black;
            label4.ForeColor = System.Drawing.Color.Black;
            label5.ForeColor = System.Drawing.Color.Red;
            label6.ForeColor = System.Drawing.Color.Black;


            txtIE.Visible = true;
            txtWin.Visible = false;
            txtPPT.Visible = false;
            txtWord.Visible = false;
            txtExcel.Visible = false;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            //放大字体
            if (txtWin.Font.Size <= 22)
            {

                int fontWinSize = int.Parse(this.txtWin.Font.Size.ToString()) + 2;
                txtWin.Font = new Font(txtWin.Font.Name, fontWinSize);
                txtExcel.Font = new Font(txtExcel.Font.Name, fontWinSize);
                txtIE.Font = new Font(txtWin.Font.Name, fontWinSize);
                txtPPT.Font = new Font(txtWin.Font.Name, fontWinSize);
                txtWord.Font = new Font(txtWin.Font.Name, fontWinSize);
                button5.Enabled = true;
            }
            else
            {
                button4.Enabled = false;
                button5.Enabled = true;
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            //缩小字体
            if (txtWin.Font.Size > 12)
            {
                int fontWinSize = int.Parse(this.txtWin.Font.Size.ToString()) - 2;
                txtWin.Font = new Font(txtWin.Font.Name, fontWinSize);
                txtExcel.Font = new Font(txtExcel.Font.Name, fontWinSize);
                txtIE.Font = new Font(txtWin.Font.Name, fontWinSize);
                txtPPT.Font = new Font(txtWin.Font.Name, fontWinSize);
                txtWord.Font = new Font(txtWin.Font.Name, fontWinSize);
                button4.Enabled = true;
            }
            else
            {
                button5.Enabled = false;
                button4.Enabled = true;
            }
        }


        #region 打开IE浏览器--韩梦甜-2015-12-14 修改人：李金颖-更改路径-2018-12-9 18:41:54
        /// <summary>
        /// 打开IE浏览器-韩梦甜-2015-12-14 修改人：李金颖-更改路径-
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnIE_Click(object sender, EventArgs e)
        {
            string paperType;
            paperType = MyInfo.MyPaperType();
            Process.Start(@"IExplore.exe", @"D:\" + MyInfo.MystudentID() + @"\计算机一级考生文件\"+ paperType +"卷"+@"\netkt\百度一下，你就知道.html");
        }
        #endregion

        //修改人：刘檬-点击label事件不修改其他label颜色（黑色）-2018年12月16日11:19:48
        private void label1_Click(object sender, EventArgs e)
        {
            //当前显示win题
            button1.Visible = true;    //"返回选择"按钮
            button3.Visible = false;    //上一题按钮
            btnIE.Visible = false;     //打开“IE页面”按钮
            button2.Visible = true;    //下一题按钮
            label1.ForeColor = System.Drawing.Color.Red;
            label2.ForeColor = System.Drawing.Color.Black;
            label3.ForeColor = System.Drawing.Color.Black;
            label4.ForeColor = System.Drawing.Color.Black;
            label5.ForeColor = System.Drawing.Color.Black;
            label6.ForeColor = System.Drawing.Color.Black;


            txtIE.Visible = false;
            txtWin.Visible = true;
            txtPPT.Visible = false;
            txtWord.Visible = false;
            txtExcel.Visible = false;

        }
        //修改人：刘檬-点击label事件不修改其他label颜色（黑色）-2018年12月16日11:19:48
        private void label6_Click(object sender, EventArgs e)
        {
            //当前显示选择题
            //调回到选择题
            this.Hide();
            FrmMain.frmmain.Visible = true;


            label6.ForeColor = System.Drawing.Color.Red;
            label1.ForeColor = System.Drawing.Color.Black;
            label2.ForeColor = System.Drawing.Color.Black;
            label3.ForeColor = System.Drawing.Color.Black;
            label4.ForeColor = System.Drawing.Color.Black;
            label5.ForeColor = System.Drawing.Color.Black;


            txtIE.Visible = false;
            txtWin.Visible = false;
            txtPPT.Visible = false;
            txtWord.Visible = false;
            txtExcel.Visible = false;
        }
        //修改人：刘檬-点击label事件不修改其他label颜色（黑色）-2018年12月16日11:19:48
        private void label2_Click(object sender, EventArgs e)
        {
            //当前显示word题
            button1.Visible = false;    //"返回选择"按钮
            button3.Visible = true;    //上一题按钮
            btnIE.Visible = false;     //打开“IE页面”按钮
            button2.Visible = true;    //下一题按钮
            label2.ForeColor = System.Drawing.Color.Red;
            label1.ForeColor = System.Drawing.Color.Black;
            label3.ForeColor = System.Drawing.Color.Black;
            label4.ForeColor = System.Drawing.Color.Black;
            label5.ForeColor = System.Drawing.Color.Black;
            label6.ForeColor = System.Drawing.Color.Black;


            txtIE.Visible = false;
            txtWin.Visible = false;
            txtPPT.Visible = false;
            txtWord.Visible = true;
            txtExcel.Visible = false;
        }
        //修改人：刘檬-点击label事件修改其他label颜色（黑色）-2018年12月16日11:19:48
        private void label3_Click(object sender, EventArgs e)
        {
            //当前显示excel题
            button1.Visible = false;    //"返回选择"按钮
            button3.Visible = true;    //上一题按钮
            btnIE.Visible = false;     //打开“IE页面”按钮
            button2.Visible = true;    //下一题按钮
            label3.ForeColor = System.Drawing.Color.Red;
            label1.ForeColor = System.Drawing.Color.Black;
            label2.ForeColor = System.Drawing.Color.Black;
            label4.ForeColor = System.Drawing.Color.Black;
            label5.ForeColor = System.Drawing.Color.Black;
            label6.ForeColor = System.Drawing.Color.Black;


            txtIE.Visible = false;
            txtWin.Visible = false;
            txtPPT.Visible = false;
            txtWord.Visible = false;
            txtExcel.Visible = true;
        }
        //修改人：刘檬-点击label事件不修改其他label颜色（黑色）-2018年12月16日11:19:48
        private void label4_Click(object sender, EventArgs e)
        {
            //当前显示ppt题
            button1.Visible = false;    //"返回选择"按钮
            button3.Visible = true;    //上一题按钮
            btnIE.Visible = false;     //打开“IE页面”按钮
            button2.Visible = true;    //下一题按钮
            label4.ForeColor = System.Drawing.Color.Red;
            label1.ForeColor = System.Drawing.Color.Black;
            label2.ForeColor = System.Drawing.Color.Black;
            label3.ForeColor = System.Drawing.Color.Black;
            label5.ForeColor = System.Drawing.Color.Black;
            label6.ForeColor = System.Drawing.Color.Black;

            txtIE.Visible = false;
            txtWin.Visible = false;
            txtPPT.Visible = true;
            txtWord.Visible = false;
            txtExcel.Visible = false;
        }

        private Point mouseOffset; 　　　　//记录鼠标指针的坐标   
        private bool isMouseDown = false; //记录鼠标按键是否按下

        private void frmMain2_MouseMove(object sender, MouseEventArgs e)
        {
            if (isMouseDown)
            {
                Point mousePos = Control.MousePosition;
                mousePos.Offset(mouseOffset.X, mouseOffset.Y);
                Location = mousePos;
            }
        }

        private void frmMain2_MouseDown(object sender, MouseEventArgs e)
        {
            int xOffset;
            int yOffset;
            if (e.Button == MouseButtons.Left)
            {
                xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
                yOffset = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height;
                mouseOffset = new Point(xOffset, yOffset);
                isMouseDown = true;
            }
        }

        private void frmMain2_MouseUp(object sender, MouseEventArgs e)
        {
            // 修改鼠标状态isMouseDown的值   
            // 确保只有鼠标左键按下并移动时，才移动窗体   
            if (e.Button == MouseButtons.Left)
            {
                isMouseDown = false;
            }
        }

        private void btnStudentFile_Click(object sender, EventArgs e)
        {
            //打开考生目录
            string path = string.Format("D:\\" + MyInfo.MystudentID() + "\\计算机一级考生文件\\" + MyInfo.MyPaperType() + "卷\\");
            Process.Start("explorer.exe", path);
        }

    }
}
